<extend name="Base/common"/>

<block name="body">
	<div class="mui-content">
	    <form id="form_add" action="{:U('add')}" method="post" enctype="multipart/form-data">
	        <div class="mui-input-row">
	            <label>标题:</label>
	            <input type="text" name="title" class="mui-text-right" placeholder="标题" value="{$goods_info.title|default=''}">
	        </div>
	        <eq name="prize" value="cash">	        	
	        <div class="mui-input-row">
	            <label>商品价格:</label>
	            <input type="text" name="goods_price" class="mui-text-right" value="{$goods_info.price|default=''}">
	            <input type="hidden" name="goods_id" id="goods_id" value="{$goods_info.id}" />
	        </div>
	        </eq>
	        <div class="mui-input-row">
	            <label>开始时间:</label>
	            <input type="text" name="start_time" class="mui-text-right" id="start_time" placeholder="开始时间">
	        </div>
	        <div class="mui-input-row">
	            <label>结束时间:</label>
	            <input type="text" name="end_time" class="mui-text-right" id="end_time" placeholder="结束时间">
	        </div>
	        <div class="mui-input-row">
	            <label>总需人数:</label>
	            <input type="number" name="total_num" class="mui-text-right" placeholder="总需人数">
	        </div>
	        <div class="mui-input-row">
	            <label>每份价格:</label>
	            <select name="money" style="direction: rtl;padding-right: 1rem;color: #666">
	            	<option value="1">1元</option>
	            	<option value="5">5元</option>
	            	<option value="10">10元</option>
	            	<option value="20">20元</option>
	            	<option value="50">50元</option>
	            	<option value="100">100元</option>
	            </select>
	        </div>
	        <div class="mui-input-row">
	            <label>中奖物品:</label>
	            <div class="prize_name mui-text-right">
	            	<eq name="prize" value="cash">
	            		现金
	            		<else />
	            		钻石
	            	</eq>
            	<input type="hidden" name="prize" id="prize" value="{$prize}" />
	            </div>
	        </div>
	        <div class="mui-input-row">
	            <label>上传图片:</label>
	            <input type="file" accept="image/*" name="pic" id="input_pic" class="mui-text-right">
	        </div>
	        <div class="mui-input-row">
	            <label>上传视频:</label>
	            <input type="file" accept="video/mp4" name="video" id="input_video" class="mui-text-right">
	        </div>
        <div class="rules">
        	<span class="mui-icon icon_allow"></span>
        	我已同意<a href="{:U('rule')}">平台发布规则</a>
        </div>
        <div style="font-size: 0.8rem;color: #999;text-align: center;">* 有机率获取</div>
		<div class="float_btn_join">
			<button type="button" id="btn_submit" class="mui-btn">立即发起</button>
		</div>
	    </form>
	</div>
</block>
<block name="script">
    <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
    <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <script type="text/javascript">
    $(function(){
        $('#start_time').datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
            language:"zh-CN",
            autoclose:true
        }).on("click",function(){
        	$("#start_time").datetimepicker("setEndDate", $("#end_time").val());
        });
        $('#end_time').datetimepicker({
            format: 'yyyy-mm-dd hh:ii',
            language:"zh-CN",
            autoclose:true
        }).on("click",function(){
        	$("#end_time").datetimepicker("setStartDate", $("#start_time").val());
        });
        $("#btn_submit").on('click',function(){
        	mui.alert('正在提交，请稍候~','',[])
	        var jsonData = new FormData($("#form_add")[0]); 
	        jsonData.append('pic', $("#input_pic")[0].files[0]);  
	        jsonData.append('video', $("#input_video")[0].files[0]); 
	        $.ajax({  
				url : "{:U('add')}",  
				type : "POST",  
				enctype: 'multipart/form-data',
				dataType: "json",
				data : jsonData,
				contentType: false,
				processData: false,  
				success : function(result) {
					mui.closePopup();
					if (result.status == 1) {
						var url = "http://{$Think.server.server_name}"+result.url;
						try{
							window.android.getUrl(url);
						}catch(e){} 
						mui.confirm("<p>分享网址:</p><textarea style='height:6rem;'>"+url + "</textarea>",result.info,['确定'],function(e){
							location.href=result.url;
						});
					}else{
						mui.confirm(result.info,'错误',['确定'],function(e){
							if (result.url !== '') {
								location.href=result.url;
							}
						});
					}
				},  
				error : function(data) {  
					console.log(data);
				}  
			});  
        });
    });
    </script>
</block>
